home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / uucico_s.lha / xferstat.c < prev    next >
C/C++ Source or Header  |  1992-12-04  |  3KB  |  131 lines

  1. /* Original by Andrew Kopp, modified by John Bickers */
  2. /* small mods for logging device, unit, and failed messages by Steve Drew */
  3.  
  4. #include "includes.h"
  5.  
  6.  
  7. Prototype void xferinit(char *);
  8. Prototype void xferstat(char *phonenum, char *comment);
  9. Prototype void xferlog(char *,...);
  10.  
  11. Prototype XferStat xfer;
  12.  
  13. XferStat xfer;
  14.  
  15.  
  16. void    xferinit(host) /*================================================*/
  17. char    *host;
  18. {
  19. time_t  t;
  20. char    proto[sizeof(xfer.proto)];
  21.     memcpy(proto,xfer.proto,sizeof(proto));
  22.     memset(&xfer,0,sizeof(xfer));
  23.     memcpy(xfer.proto,proto,sizeof(xfer.proto));
  24.     strncpy(xfer.host,host,sizeof(xfer.host)-1);
  25.     t = time(NULL);
  26.     xfer.time_start = t;
  27.     xfer.time_stop  = t;
  28. }
  29.  
  30. void    xferstat(char *phonenum, char *comment) /*=======================*/
  31. {
  32. FILE    *fo;
  33. struct tm st,et;
  34. long    hh,mm,ss,calc,fcalc,perc;
  35.  
  36.     if (xfer.flags & XFERF_WRITTEN) return;
  37.  
  38.     fo = fopen("uuspool:xferstat","a");
  39.     if (!fo) return;
  40.  
  41.     xfer.flags |= XFERF_WRITTEN;   /* indicate output done */
  42.  
  43.   /* Indicator for type of link   */
  44.     fprintf(fo,"%c %-8s ",(xfer.flags & XFERF_OUTGOING)? '<': '>',xfer.host);
  45.  
  46.     st = *localtime(&xfer.time_start);
  47.     et = *localtime(&xfer.time_stop);
  48.  
  49.     fprintf(fo,"%02d-%02d-%02d %02d:%02d:%02d > ",st.tm_mday,st.tm_mon+1,st.tm_year,st.tm_hour,st.tm_min,st.tm_sec);
  50.     fprintf(fo,"%02d-%02d-%02d %02d:%02d:%02d ",et.tm_mday,et.tm_mon+1,et.tm_year,et.tm_hour,et.tm_min,et.tm_sec);
  51.  
  52.     hh = et.tm_hour - st.tm_hour;
  53.     if (hh < 0) hh += 24;
  54.     mm = et.tm_min  - st.tm_min;
  55.     ss = et.tm_sec  - st.tm_sec;
  56.     if (ss < 0) {
  57.         ss += 60;
  58.         mm--;
  59.     }
  60.     if (mm < 0) {
  61.         mm += 60;
  62.         hh--;
  63.     }
  64.     if (hh < 0) hh += 24;
  65.  
  66.     fprintf(fo,"(%02d:%02d:%02d)",hh,mm,ss);
  67.  
  68.     ss += (hh * 3600L) + (mm * 60L);
  69.  
  70.     calc = xfer.bytes_recv + xfer.bytes_send;
  71.     calc = (ss)? calc/ss: 0L;
  72.     fprintf(fo,"%6ld",calc);
  73.  
  74.     fcalc = xfer.fbytes_recv + xfer.fbytes_send;
  75.     fcalc = (ss)? fcalc/ss: 0L;
  76.     fprintf(fo," %6ld",fcalc);
  77.  
  78.     perc = (calc)? (100 * fcalc)/calc: 0L;
  79.     fprintf(fo," %3ld%%\n",perc);
  80.  
  81.     switch(xfer.proto[0]) {
  82.         case ('g'):
  83.         case ('G'):
  84.             {
  85.             int     psize;
  86.                 psize = (1 << (xfer.proto[2] + 4));
  87.                 fprintf(fo,"| %c %1d %4d",xfer.proto[0],xfer.proto[1],psize);
  88.             }
  89.             break;
  90.         default:
  91.             fprintf(fo,"|         ");
  92.     }
  93.     fprintf(fo," %8ld %8ld # %8ld %8ld # %4ld %4ld\n",
  94.             xfer.bytes_recv,xfer.bytes_send,
  95.             xfer.fbytes_recv,xfer.fbytes_send,
  96.             xfer.files_recv,xfer.files_send
  97.            );
  98.     /*
  99.      * serial port, and comment passed from uucico mods by Steve Drew
  100.      */
  101.     {
  102.         extern char *DeviceName;
  103.     extern long DeviceUnit;
  104.  
  105.         fprintf(fo,"| VIA device %s unit %d", DeviceName,DeviceUnit);
  106.         if (phonenum) {
  107.             fprintf(fo," number %s\n",phonenum);
  108.         }
  109.         else fprintf(fo,"\n");
  110.         
  111.         if (comment != NULL) {
  112.             fprintf(fo,"%s\n",comment);
  113.         }
  114.     }
  115.     
  116.     fclose(fo);
  117. }
  118.  
  119. /* Perhaps put file handle into xfer? */
  120. void    xferlog(char *cp,...) /*=========================================*/
  121. {
  122. FILE    *fo;
  123. va_list args;
  124.     if (cp && fo = fopen("uuspool:xferstat","a")) {
  125.         va_start(args,cp);
  126.         vfprintf(fo,cp,args)
  127.         va_end(args);
  128.         fclose(fo);
  129.     }
  130. }
  131.